package ru.jexp.rcp.supply.swtext;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Composite;

public abstract class JExpCTabFolder
{
	public abstract CTabItem createItem(int index);

	private CTabFolder folder;

	public JExpCTabFolder(Composite parent, int style)
	{
		folder = new CTabFolder(parent, style);
	}

	public void removeItem(int index)
	{
		folder.getItem(index).dispose();
	}

	public void setMenu(MenuManager mng)
	{
		folder.setMenu(mng.createContextMenu(folder));
	}

	protected CTabFolder getFolder()
	{
		return folder;
	}

	public void setLayoutData(Object layoutData)
	{
		folder.setLayoutData(layoutData);
	}

	public void setSelection(int index)
	{
		folder.setSelection(index);
	}

	public void addSelectionListener(SelectionListener listener)
	{
		folder.addSelectionListener(listener);
	}

	public int getSelection()
	{
		return folder.getSelectionIndex();
	}

	public CTabItem getSelectionItem()
	{
		return folder.getSelection();
	}

	public CTabItem getItem(int index)
	{
		return folder.getItem(index);
	}

	public CTabItem[] getItems()
	{
		return folder.getItems();
	}

	public int getItemCount()
	{
		return folder.getItemCount();
	}

	public void removeAll()
	{
		CTabItem[] items = getItems();
		for (int i = 0; i < items.length; i++)
		{
			items[i].dispose();
		}
	}
}
